{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exploring the WMS with OWSLib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "surface_flag\n",
      "CRW_DHW\n",
      "CRW_HOTSPOT\n",
      "CRW_SST\n",
      "CRW_SSTANOMALY\n"
     ]
    }
   ],
   "source": [
    "from owslib.wms import WebMapService\n",
    "\n",
    "\n",
    "url = 'http://oos.soest.hawaii.edu/thredds/wms/hioos/satellite/dhw_5km'\n",
    "\n",
    "web_map_services = WebMapService(url)\n",
    "\n",
    "print('\\n'.join(web_map_services.contents.keys()))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Layer metadata"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "layer = 'CRW_SST'\n",
    "wms = web_map_services.contents[layer]\n",
    "\n",
    "name = wms.title\n",
    "\n",
    "lon = (wms.boundingBox[0] + wms.boundingBox[2]) / 2.\n",
    "lat = (wms.boundingBox[1] + wms.boundingBox[3]) / 2.\n",
    "center = lat, lon\n",
    "\n",
    "time_interval = '{0}/{1}'.format(\n",
    "    wms.timepositions[0].strip(),\n",
    "    wms.timepositions[-1].strip()\n",
    ")\n",
    "style = 'boxfill/sst_36'\n",
    "\n",
    "if style not in wms.styles:\n",
    "    style = None"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Single layer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idG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AgICAgICAgICAgICAgIHZhciBib3VuZHMgPSBudWxsOwogICAgICAgICAgICAKCiAgICAgICAgICAgIHZhciBtYXBfYjk3NGIxY2U1M2I5NGM2NmFjNDRiNmI5ODE5NTk3ODkgPSBMLm1hcCgKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdtYXBfYjk3NGIxY2U1M2I5NGM2NmFjNDRiNmI5ODE5NTk3ODknLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge2NlbnRlcjogWy00MCwtNTBdLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgem9vbTogNSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1heEJvdW5kczogYm91bmRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGF5ZXJzOiBbXSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmxkQ29weUp1bXA6IGZhbHNlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgTC5jb250cm9sLnNjYWxlKCkuYWRkVG8obWFwX2I5NzRiMWNlNTNiOTRjNjZhYzQ0YjZiOTgxOTU5Nzg5KTsKICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgdGlsZV9sYXllcl9kZjUwZDgxYjk3ZmM0MDI5OTA1MWNhYzE0ZGE4YzQ4NiA9IEwudGlsZUxheWVyKAogICAgICAgICAgICAgICAgJ2h0dHBzOi8ve3N9LnRpbGUub3BlbnN0cmVldG1hcC5vcmcve3p9L3t4fS97eX0ucG5nJywKICAgICAgICAgICAgICAgIHsKICAiYXR0cmlidXRpb24iOiBudWxsLAogICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAibWF4Wm9vbSI6IDE4LAogICJtaW5ab29tIjogMSwKICAibm9XcmFwIjogZmFsc2UsCiAgInN1YmRvbWFpbnMiOiAiYWJjIgp9CiAgICAgICAgICAgICAgICApLmFkZFRvKG1hcF9iOTc0YjFjZTUzYjk0YzY2YWM0NGI2Yjk4MTk1OTc4OSk7CiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIG1hY3JvX2VsZW1lbnRfZThmMTEyODQxMTAyNGE2Yjk4ZjdmZjcwOGVhNTE4YzcgPSBMLnRpbGVMYXllci53bXMoCiAgICAgICAgICAgICAgICAnaHR0cDovL29vcy5zb2VzdC5oYXdhaWkuZWR1L3RocmVkZHMvd21zL2hpb29zL3NhdGVsbGl0ZS9kaHdfNWttJywKICAgICAgICAgICAgICAgIHsKICAiYXR0cmlidXRpb24iOiAiIiwKICAiY3JzIjogbnVsbCwKICAiZm9ybWF0IjogImltYWdlL3BuZyIsCiAgImxheWVycyI6ICJDUldfU1NUIiwKICAic3R5bGVzIjogImJveGZpbGwvc3N0XzM2IiwKICAidHJhbnNwYXJlbnQiOiB0cnVlLAogICJ1cHBlcmNhc2UiOiBmYWxzZSwKICAidmVyc2lvbiI6ICIxLjEuMSIKfQogICAgICAgICAgICAgICAgKS5hZGRUbyhtYXBfYjk3NGIxY2U1M2I5NGM2NmFjNDRiNmI5ODE5NTk3ODkpOwoKICAgICAgICAKICAgIAogICAgICAgICAgICBtYXBfYjk3NGIxY2U1M2I5NGM2NmFjNDRiNmI5ODE5NTk3ODkudGltZURpbWVuc2lvbiA9IEwudGltZURpbWVuc2lvbih7CiAgICAgICAgICAgICAgICBwZXJpb2Q6IlBUMUgiLAogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICB0aW1lSW50ZXJ2YWw6ICIyMDEzLTA2LTAzVDEyOjAwOjAwLjAwMFovMjAxNy0wOS0yMFQxMjowMDowMC4wMDBaIiwKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgfSk7CiAgICAgICAgICAgIG1hcF9iOTc0YjFjZTUzYjk0YzY2YWM0NGI2Yjk4MTk1OTc4OS50aW1lRGltZW5zaW9uQ29udHJvbCA9IEwuY29udHJvbC50aW1lRGltZW5zaW9uKHsKICAgICAgICAgICAgICAgIHBvc2l0aW9uOiAnYm90dG9tbGVmdCcsCiAgICAgICAgICAgICAgICBhdXRvUGxheTogZmFsc2UsCiAgICAgICAgICAgICAgICBwbGF5ZXJPcHRpb25zOiB7CiAgICAgICAgICAgICAgICAgICAgdHJhbnNpdGlvblRpbWU6IDIwMCwKICAgICAgICAgICAgICAgICAgICBsb29wOiBmYWxzZX0KICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgbWFwX2I5NzRiMWNlNTNiOTRjNjZhYzQ0YjZiOTgxOTU5Nzg5LmFkZENvbnRyb2wobWFwX2I5NzRiMWNlNTNiOTRjNjZhYzQ0YjZiOTgxOTU5Nzg5LnRpbWVEaW1lbnNpb25Db250cm9sKTsKCiAgICAgICAgICAgIAogICAgICAgICAgICB2YXIgbWFjcm9fZWxlbWVudF9lOGYxMTI4NDExMDI0YTZiOThmN2ZmNzA4ZWE1MThjNyA9IEwudGltZURpbWVuc2lvbi5sYXllci53bXMobWFjcm9fZWxlbWVudF9lOGYxMTI4NDExMDI0YTZiOThmN2ZmNzA4ZWE1MThjNywKICAgICAgICAgICAgICAgIHt1cGRhdGVUaW1lRGltZW5zaW9uOiBmYWxzZSwKICAgICAgICAgICAgICAgICB3bXNWZXJzaW9uOiAnJywKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICkuYWRkVG8obWFwX2I5NzRiMWNlNTNiOTRjNjZhYzQ0YjZiOTgxOTU5Nzg5KTsKICAgICAgICAgICAgCiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIGxheWVyX2NvbnRyb2xfY2I0MDFhYzQyMzFlNGQzMmJlMWNkZjdmZGFlOTc3ZjYgPSB7CiAgICAgICAgICAgICAgICBiYXNlX2xheWVycyA6IHsgIm9wZW5zdHJlZXRtYXAiIDogdGlsZV9sYXllcl9kZjUwZDgxYjk3ZmM0MDI5OTA1MWNhYzE0ZGE4YzQ4NiwgfSwKICAgICAgICAgICAgICAgIG92ZXJsYXlzIDogeyAic2VhX3N1cmZhY2VfdGVtcGVyYXR1cmUiIDogbWFjcm9fZWxlbWVudF9lOGYxMTI4NDExMDI0YTZiOThmN2ZmNzA4ZWE1MThjNywgfQogICAgICAgICAgICAgICAgfTsKICAgICAgICAgICAgTC5jb250cm9sLmxheWVycygKICAgICAgICAgICAgICAgIGxheWVyX2NvbnRyb2xfY2I0MDFhYzQyMzFlNGQzMmJlMWNkZjdmZGFlOTc3ZjYuYmFzZV9sYXllcnMsCiAgICAgICAgICAgICAgICBsYXllcl9jb250cm9sX2NiNDAxYWM0MjMxZTRkMzJiZTFjZGY3ZmRhZTk3N2Y2Lm92ZXJsYXlzLAogICAgICAgICAgICAgICAge3Bvc2l0aW9uOiAndG9wcmlnaHQnLAogICAgICAgICAgICAgICAgIGNvbGxhcHNlZDogdHJ1ZSwKICAgICAgICAgICAgICAgICBhdXRvWkluZGV4OiB0cnVlCiAgICAgICAgICAgICAgICB9KS5hZGRUbyhtYXBfYjk3NGIxY2U1M2I5NGM2NmFjNDRiNmI5ODE5NTk3ODkpOwogICAgICAgIAo8L3NjcmlwdD4=\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7ff4a9b6a588>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import folium\n",
    "from folium import plugins\n",
    "\n",
    "lon, lat = -50, -40\n",
    "\n",
    "m = folium.Map(\n",
    "    location=[lat, lon],\n",
    "    zoom_start=5,\n",
    "    control_scale=True\n",
    ")\n",
    "\n",
    "w = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name=name,\n",
    "    styles=style,\n",
    "    fmt='image/png',\n",
    "    transparent=True,\n",
    "    layers=layer,\n",
    "    overlay=True,\n",
    "    COLORSCALERANGE='1.2,28',\n",
    ")\n",
    "\n",
    "w.add_to(m)\n",
    "\n",
    "time = plugins.TimestampedWmsTileLayers(\n",
    "    w,\n",
    "    period='PT1H',\n",
    "    time_interval=time_interval\n",
    ")\n",
    "\n",
    "time.add_to(m)\n",
    "\n",
    "folium.LayerControl().add_to(m)\n",
    "\n",
    "m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Multiple layers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><iframe src=\"data:text/html;charset=utf-8;base64,PCFET0NUWVBFIGh0bWw+CjxoZWFkPiAgICAKICAgIDxtZXRhIGh0dHAtZXF1aXY9ImNvbnRlbnQtdHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PVVURi04IiAvPgogICAgPHNjcmlwdD5MX1BSRUZFUl9DQU5WQVMgPSBmYWxzZTsgTF9OT19UT1VDSCA9IGZhbHNlOyBMX0RJU0FCTEVfM0QgPSBmYWxzZTs8L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2Nkbi5qc2RlbGl2ci5uZXQvbnBtL2xlYWZsZXRAMS4yLjAvZGlzdC9sZWFmbGV0LmpzIj48L3NjcmlwdD4KICAgIDxzY3JpcHQgc3JjPSJodHRwczovL2FqYXguZ29vZ2xlYXBpcy5jb20vYWpheC9saWJzL2pxdWVyeS8xLjExLjEvanF1ZXJ5Lm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9tYXhjZG4uYm9vdHN0cmFwY2RuLmNvbS9ib290c3RyYXAvMy4yLjAvanMvYm9vdHN0cmFwLm1pbi5qcyI+PC9zY3JpcHQ+CiAgICA8c2NyaXB0IHNyYz0iaHR0cHM6Ly9jZG5qcy5jbG91ZGZsYXJlLmNvbS9ham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0dHBzOi8vY2RuanMuY2xvdWRmbGFyZS5jb20vYWpheC9saWJzL2hpZ2hsaWdodC5qcy84LjQvc3R5bGVzL2RlZmF1bHQubWluLmNzcyIgLz4KICAgIDxsaW5rIHJlbD0ic3R5bGVzaGVldCIgaHJlZj0iaHR0cDovL2FwcHMuc29jaWIuZXMvTGVhZmxldC5UaW1lRGltZW5zaW9uL2Rpc3QvbGVhZmxldC50aW1lZGltZW5zaW9uLmNvbnRyb2wubWluLmNzcyIgLz4KPC9oZWFkPgo8Ym9keT4gICAgCiAgICAKICAgICAgICAgICAgPGRpdiBjbGFzcz0iZm9saXVtLW1hcCIgaWQ9Im1hcF81NTUwNTg1ODRiNTA0YmMxYjQ0ODVhZTA2ZWE2ZDU4ZSIgPjwvZGl2PgogICAgICAgIAo8L2JvZHk+CjxzY3JpcHQ+ICAgIAogICAgCgogICAgICAgICAgICAKICAgICAgICAgICAgICAgIHZhciBib3VuZHMgPSBudWxsOwogICAgICAgICAgICAKCiAgICAgICAgICAgIHZhciBtYXBfNTU1MDU4NTg0YjUwNGJjMWI0NDg1YWUwNmVhNmQ1OGUgPSBMLm1hcCgKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdtYXBfNTU1MDU4NTg0YjUwNGJjMWI0NDg1YWUwNmVhNmQ1OGUnLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAge2NlbnRlcjogWy00MCwtNTBdLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgem9vbTogNSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1heEJvdW5kczogYm91bmRzLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGF5ZXJzOiBbXSwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHdvcmxkQ29weUp1bXA6IGZhbHNlLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY3JzOiBMLkNSUy5FUFNHMzg1NwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9KTsKICAgICAgICAgICAgTC5jb250cm9sLnNjYWxlKCkuYWRkVG8obWFwXzU1NTA1ODU4NGI1MDRiYzFiNDQ4NWFlMDZlYTZkNThlKTsKICAgICAgICAKICAgIAogICAgICAgICAgICB2YXIgdGlsZV9sYXllcl9lOTVlMThjNzFiYTg0MzgxOTIyODc4OWViMGE3NjVjOSA9IEwudGlsZUxheWVyKAogICAgICAgICAgICAgICAgJ2h0dHBzOi8ve3N9LnRpbGUub3BlbnN0cmVldG1hcC5vcmcve3p9L3t4fS97eX0ucG5nJywKICAgICAgICAgICAgICAgIHsKICAiYXR0cmlidXRpb24iOiBudWxsLAogICJkZXRlY3RSZXRpbmEiOiBmYWxzZSwKICAibWF4Wm9vbSI6IDE4LAogICJtaW5ab29tIjogMSwKICAibm9XcmFwIjogZmFsc2UsCiAgInN1YmRvbWFpbnMiOiAiYWJjIgp9CiAgICAgICAgICAgICAgICApLmFkZFRvKG1hcF81NTUwNTg1ODRiNTA0YmMxYjQ0ODVhZTA2ZWE2ZDU4ZSk7CiAgICAgICAgCiAgICAKICAgICAgICAgICAgdmFyIG1hY3JvX2VsZW1lbnRfZjIxMjM5Mjc4MThmNGYwNmIzMTYzODlmN2U1MDAzNWUgPSBMLnRpbGVMYXllci53bXMoCiAgICAgICAgICAgICAgICAnaHR0cDovL29vcy5zb2VzdC5oYXdhaWkuZWR1L3RocmVkZHMvd21zL2hpb29zL3NhdGVsbGl0ZS9kaHdfNWttJywKICAgICAgICAgICAgICAgIHsKICAiYXR0cmlidXRpb24iOiAiIiwKICAiY3JzIjogbnVsbCwKICAiZm9ybWF0IjogImltYWdlL3BuZyIsCiAgImxheWVycyI6ICJDUldfU1NUIiwKICAic3R5bGVzIjogImJveGZpbGwvc3N0XzM2IiwKICAidHJhbnNwYXJlbnQiOiB0cnVlLAogICJ1cHBlcmNhc2UiOiBmYWxzZSwKICAidmVyc2lvbiI6ICIxLjEuMSIKfQogICAgICAgICAgICAgICAgKS5hZ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WFwXzU1NTA1ODU4NGI1MDRiYzFiNDQ4NWFlMDZlYTZkNThlKTsKICAgICAgICAKPC9zY3JpcHQ+\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
      ],
      "text/plain": [
       "<folium.folium.Map at 0x7ff48f737668>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m = folium.Map(\n",
    "    location=[lat, lon],\n",
    "    zoom_start=5,\n",
    "    control_scale=True\n",
    ")\n",
    "\n",
    "w0 = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name='sea_surface_temperature',\n",
    "    styles=style,\n",
    "    fmt='image/png',\n",
    "    transparent=True,\n",
    "    layers='CRW_SST',\n",
    "    overlay=True,\n",
    ")\n",
    "\n",
    "w1 = folium.raster_layers.WmsTileLayer(\n",
    "    url=url,\n",
    "    name='analysed sea surface temperature anomaly',\n",
    "    styles=style,\n",
    "    fmt='image/png',\n",
    "    transparent=True,\n",
    "    layers='CRW_SSTANOMALY',\n",
    "    overlay=True,\n",
    ")\n",
    "\n",
    "w0.add_to(m)\n",
    "w1.add_to(m)\n",
    "\n",
    "time = folium.plugins.TimestampedWmsTileLayers(\n",
    "    [w0, w1],\n",
    "    period='PT1H',\n",
    "    time_interval=time_interval\n",
    ")\n",
    "\n",
    "time.add_to(m)\n",
    "\n",
    "folium.LayerControl().add_to(m)\n",
    "\n",
    "m"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
